package com.dubbo.cp.consumer.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dubbo.cp.consumer.service.SeataService;
import com.dubbo.cp.service.DemoService;
import com.dubbo.cp.service.LogService;
import com.dubbo.cp.service.PayService;
import com.dubbo.cp.service.UserService;

import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;

@RestController
public class SeataDemoController {
	
    @Reference
    private DemoService demoServiceImpl;
    
    @Reference
    private PayService payService;

    @Reference
    private LogService logService;
    
    @Autowired
    private SeataService seataService ;
    
	@RequestMapping("/seata")
//	@GlobalTransactional(rollbackFor = Exception.class)
	public String seataTest() {
//		System.out.println("开始全局事务，XID = " + RootContext.getXID());
//		logService.sendDemoLog("访问 DEMO seata");
//		payService.doPay();
//
//		logService.sendUserLog("Admin", "访问 DEMO seata");
//		demoServiceImpl.sayHello();

		if(!seataService.pay()) {
		throw new RuntimeException();
	}

		return "/seata";
	}
}
